import { ref, watchEffect } from 'vue'
import { defineStore } from 'pinia'
import { getCartListReq } from '@/api/cart'

// 定义购物车的 store
export const useCartStore = defineStore('cart', () => {
  let CartList = ref([])
  let CartTypeNum = ref(0)
  async function getCartList() {
    let res = await getCartListReq()
    CartList.value = res.data.data
  }
  getCartList()
  watchEffect(() => {
    CartTypeNum.value = CartList.value.length
  })
  return { CartList, CartTypeNum, getCartList }
})
